package search_service

import (
	"peilian-api/app/global/common"
	"peilian-api/app/global/errors"
	"peilian-api/app/global/variable"
	"peilian-api/app/model"

	"github.com/gin-gonic/gin"
)

type RedisSearch struct{}

func (*RedisSearch) GetSchool(ctx *gin.Context, srs model.SchoolRedisSearch) ([]string, *errors.ErrRes) {
	query := srs.Query
	sc := variable.DB.Redis.
		SScan(common.RedisSchoolKey, 0, "*"+query+"*", 30000)
	if sc.Err() != nil {
		return []string{}, nil
	}
	out, _, err := sc.Result()
	if err != nil {
		return []string{}, nil
	}
	return out, nil
}
